<link rel="stylesheet" href="/resource/kalendae/build/kalendae.css" type="text/css" charset="utf-8">
<script src="/resource/kalendae/build/kalendae.activity.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
.datesel { background-color: #eee; display: inline-block; width: 480px;border: 1px solid  #e5e5e5;  }
.tbcal { width: 100%;  }
.tbcal .left { width: 30%; }
.tbcal .right{ position: relative; width: 70%;  }
.kalendae .k-days span.closed {
	background:red;
}
.datesel .left .time { padding-left: 20px; color: #898989; font-size: 14px; }
.datesel .left .time input { display: block; width: 134px; height: 40px; background: #fff url(/resource/www/imgs/date_icon.png) no-repeat 10px 6px; padding-left: 40px; }

.kalendae .k-calendar { width: 290px; }
.k-title { position: relative; }
.k-title .k-caption { position: relative; top: 0px ; }
.kalendae .k-title, .kalendae .k-header, .kalendae .k-days { width: 266px; text-align: center; margin: 0 auto; }
.kalendae .k-days span { background: #ccc; width: 34px; height: 34px; line-height: 34px; text-align: center; padding: 0; margin: 2px; }
.kalendae .k-header span {  width: 36px; height: 36px; line-height: 36px; text-align: center; }

.kalendae .k-caption {  font-weight: bold; font-size: 18px;   color: #262626;}

.tbcal .mulcal {  width: 290px; position: relative;}

.kalendae .k-days span.k-in-month.k-active { background: #fff; color: #444; }
.kalendae .k-days span.k-in-month { color: #fff; }
.kalendae .k-days span.k-selected.k-active {  background: #2cda98; color: #fff; }
.kalendae .k-days span.k-out-of-month{color:#fff;}
</style>

<script>

var global_kal = null;
var global_kal2 = null;

function getWeeklyDatesBetweenDays (day1, day2, wDay)
{
    if (wDay == '周日')
        iW = 0;
    else if (wDay == '周一')
        iW = 1;
    else if (wDay == '周二')
        iW = 2;
    else if (wDay == '周三')
        iW = 3;
    else if (wDay == '周四')
        iW = 4;
    else if (wDay == '周五')
        iW = 5;
    else if (wDay == '周六')
        iW = 6;

    d1 = new Date(day1);
    d2 = new Date(day2);
    dx = d1;
    i  = 0;

    global_kal.setSelected();

    for (; dx.getTime() <= d2.getTime(); i = i + 1 )
    {
        if (dx.getDay() == iW)
        {
            global_kal.addSelected(dx.toDateString());
        }

        dx.setTime(dx.getTime() + 86400000);
    }

    global_kal.draw();
}

function init_calendar (elementId)
{
    if ($('#' + elementId).length <= 0) 
        return;

    js_global_var = new Kalendae.Input(elementId, {
            attachTo: document.getElementById(elementId),
			months:1,
            weekStart: 1,
			mode:'single',
            useYearNav: false,
            direction:'today-future',
            columnHeaderFormat: "dd",
            titleFormat: "YYYY年MM月",
            format: 'YYYY-MM-DD',
            disableNextMonth: true,
            blackout : function (x) {
                return false;
            },

            'subscribe' : {
                'date-clicked' : function (date) {
                    //
                    var date1 = global_kal.getSelected();
                    if(elementId == 'end'){
                        if(date.isBefore(date1)){
                        layer.msg("结束日期不能在出发日期之前");
                            global_kal2.setSelected();
                            return false;
                        }
                    }

                }
            },
		});

    return js_global_var;
}


$(document).ready(function () {

    global_kal = init_calendar('start');
    global_kal2 = init_calendar('end');

    //global_kal.viewStartDate = Kalendae.moment(guiderFreeDays[0]);
    //global_kal.draw();
});

</script>
